function freq = volt2detuning(vIn)

% Input is the voltage applied to the lock system. 
% Returns the estimated detuning of the cooling laser from resonance with
% the Rb87 D2 F = 2 -> F' = 3 transition.
% -5.5 V is approximately resonance, and -3.6 V is about 2.5 Gamma below
% resonance (i.e. a good MOT frequency). 

cons = Constants();

offset = 162.1630; % Measured on 18/10/2013.
% Before this date this value was 158. 

offset = 160.3035; % Measured on 25/11/2013.
% Had some problems with the locking system and the lock point of the
% master clock changed slightly. 

offset = 158.7435; % Measured on 23/01/2014
% Had bad error signal on MTS setup, so it was realigned. 

offset = 157.4118; % Measured on 21/01/2014. Data in D:\data\2014\02\21\18_17_01
    
% v = [-5.5:0.1:-2.5 -2:3];
% f = [153.65 % Measured on 06/09/13.
%     153.63
%     154.63
%     155.89
%     157.18
%     158.52
%     159.86
%     161.2
%     162.56
%     163.93
%     165.37
%     166.78
%     168.11
%     169.42
%     170.72
%     171.98
%     173.23
%     174.48
%     175.72
%     176.96
%     178.23
%     179.49
%     180.76
%     182.05
%     183.35
%     184.69
%     186.1
%     187.51
%     188.97
%     190.48
%     192.05
%     201.15
%     226.67
%     265.36
%     320.37
%     392.68
%     471.88
%     ];

v = [-6 -5.5 -5:0.1:-2.5 -2:0.5:6];
if (min(vIn) < min(v)) || (max(vIn) > max(v))
    warning('Warning! You have gone outside the calibrated range of the lock voltage!')
end
f = [153.37 % Measured on 16/01/14.
    153.37
    158.12
    159.47
    160.81
    162.17
    163.54
    164.96
    166.37
    167.70
    168.96
    170.22
    171.42
    172.61
    173.78
    174.96
    176.13
    177.35
    178.56
    179.78
    181.04
    182.32
    183.64
    185.03
    186.44
    187.90
    189.41
    190.98
    199.92
    211.01
    224.90
    242.49
    264.33
    290.47
    320.29
    353.12
    392.15
    430.73
    470.18
    507.14
    536.97
    559.03
    575.26
    587.15
    595.64];



freq = -(spline(v,f,vIn) - offset);
end